import { Injectable } from '@nestjs/common';
import { Sys } from '../../entities/sys.entity';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { ApiErrorCode } from '../../common/enums/api-error-code.enum';
import {
  Response,
  ResponseParam,
  CurrentError,
  UserError,
} from '../../common/enums/response';
import { Utils } from '../../util/utils.service';
import { AdminRole, UserRole } from 'src/entities/user.entity';
import { Auth } from '../../auth/auth';

@Injectable()
export class SysService {
  constructor() {}
  @InjectRepository(Sys) private readonly sys: Repository<Sys>;

  public async put(smsMoney: number, phoneMoney: number) {
    await this.sys.update({ id: 1 }, { smsMoney, phoneMoney });
    let responseParam: ResponseParam = {
      message: ApiErrorCode.LACK_UPDATE_SUCCESS,
      data: null,
    };
    return Response(responseParam);
  }

  public async get() {
    const sysInfo: Sys = await this.sys.findOneBy({ id: 1 });
    let responseParam: ResponseParam = {
      message: ApiErrorCode.LACK_GET_SUCCESS,
      data: sysInfo,
    };
    return Response(responseParam);
  }
}
